package org.mzy.pet.controller;

import org.mzy.basic.anno.PreAuthorize;
import org.mzy.pet.service.IPetOnlineAuditLogService;
import org.mzy.pet.domain.PetOnlineAuditLog;
import org.mzy.pet.query.PetOnlineAuditLogQuery;
import org.mzy.basic.util.AjaxResult;
import org.mzy.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/petOnlineAuditLog")
public class PetOnlineAuditLogController {
    @Autowired
    public IPetOnlineAuditLogService petOnlineAuditLogService;


    /**
     * 保存和修改公用的
     * @param petOnlineAuditLog 传递的实体
     * @return Result转换结果
     */
    @PutMapping
    @PreAuthorize(name = "新增/修改宠物上架日志", sn = "petOnlineAuditLog:addOrUpdate")
    public AjaxResult addOrUpdate(@RequestBody PetOnlineAuditLog petOnlineAuditLog) {
        try {
            if ( petOnlineAuditLog.getId() != null)
                petOnlineAuditLogService.update(petOnlineAuditLog);
            else
                petOnlineAuditLogService.add(petOnlineAuditLog);
            return AjaxResult.me().success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().fail();
        }
    }

    /**
    * 删除对象信息
    * @param id
    * @return
    */
    @DeleteMapping(value = "/{id}")
    @PreAuthorize(name = "删除宠物上架日志", sn = "petOnlineAuditLog:delete")
    public AjaxResult delete(@PathVariable("id") Long id) {
        try {
                petOnlineAuditLogService.delete(id);
            return AjaxResult.me().success();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().fail();
        }
    }

    //获取用户
    @GetMapping("/{id}")
    @PreAuthorize(name = "根据id查询宠物上架日志", sn = "petOnlineAuditLog:get")
    public PetOnlineAuditLog get(@PathVariable("id") Long id) {
        return petOnlineAuditLogService.findById(id);
    }


    /**
    * 查看所有的员工信息
    * @return
    */
    @GetMapping()
    @PreAuthorize(name = "查询所有宠物上架日志", sn = "petOnlineAuditLog:list")
    public List<PetOnlineAuditLog> list() {

        return petOnlineAuditLogService.findAll();
    }


    /**
    * 分页查询数据
    *
    * @param query 查询对象
    * @return PageList 分页对象
    */
    @PostMapping("/list")
    @PreAuthorize(name = "分页查询宠物上架日志", sn = "petOnlineAuditLog:json")
    public PageList<PetOnlineAuditLog> json(@RequestBody PetOnlineAuditLogQuery query) {
        return petOnlineAuditLogService.queryByPage(query);
    }
}
